﻿using CMS.ViewModels;
using CMS.Views.Windows;
using CMS.Views;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Prism.DryIoc;
using DBMode;

namespace CMS
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void OnInitialized()
        {
            var dialog = Container.Resolve<IDialogService>();
            dialog.ShowDialog("LoginView", callback =>
            {
                if (callback.Result!=ButtonResult.OK) { Environment.Exit(0);return; }
                var model = Container.Resolve<MainViewModel>();
                model.Nav();


            });
            base.OnInitialized();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainView, MainViewModel>();
            containerRegistry.RegisterForNavigation<IndexView,IndexViewModel>();
            containerRegistry.RegisterForNavigation<CommodityView,CommodityViewModel>();
            containerRegistry.RegisterForNavigation<UserView,UserViewModel>();
            containerRegistry.RegisterForNavigation<LoginView, LoginViewModel>();
            containerRegistry.RegisterForNavigation<RecordView, RecordViewModel>();

            //导航窗口
            containerRegistry.RegisterDialog<AddUserView, AddUserViewModel>();
            containerRegistry.RegisterDialog<AddCommodityView, AddCommodityViewModel>();
            containerRegistry.RegisterDialog<AddRecordView, AddRecordViewModel>();

            //方法的注入
            containerRegistry.Register<IMethods<Member>, MemberMethod>();
            containerRegistry.Register<IMethods<Commodity>, CommodityMethod>();
            containerRegistry.Register<IMethods<Record>, RecordMethod>();
        }
    }
}
